﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace CuaHangDiaNhac
{
    public class DuLieu
    {
        public static void GetValueInCombo(object value, ComboBox cb)
        {
            try
            {
                cb.SelectedValue = value;
            }
            catch (Exception)
            { }
        }
        public static void SetDataSource(ComboBox cb, DataSet ds, string dis, string value)
        {
            cb.DataSource = ds.Tables[0];
            cb.DisplayMember = dis;
            cb.ValueMember = value;
        }
        public static void SetDataSource(ComboBox cb, List<String> st, string dis, string value)
        {
            cb.DataSource = st;
            cb.DisplayMember = dis;
            cb.ValueMember = value;
        }
        public static void SetDataSource(DataGridView dgrDanhSach, DataSet ds)
        {
            dgrDanhSach.DataSource = ds.Tables[0];
        }
        public static void SetDataSource(DataGridView dgrDanhSach, object ds)
        {
            dgrDanhSach.DataSource = ds;
        }



















        public static bool SoSanh(DateTime batdau, DateTime ketthuc)
        {
            return DateTime.Parse(batdau.ToShortDateString()) <= DateTime.Parse(ketthuc.ToShortDateString());
        }
        public static DateTime ShortDateTime(DateTimePicker pk)
        {
            return DateTime.Parse(pk.Value.ToShortDateString());
        }
        public static DateTime ShortDateTime(DateTime pk)
        {
            return DateTime.Parse(pk.ToShortDateString());
        }
        public static object CellValue(DataGridView dgr, int row, int c)
        {
            try
            {
                return dgr.Rows[row].Cells[c];
            }
            catch (Exception)
            {
                return null;
            }
        }
        public static object CellValue(DataGridView dgr, int row, string columnname)
        {
            try
            {
                return dgr.Rows[row].Cells[columnname].Value;
            }
            catch (Exception)
            {
                return null;
            }
        }
        public static object CellValue(DataGridViewRow row, string columnname)
        {
            try
            {
                return row.Cells[columnname].Value;
            }
            catch (Exception)
            {
                return null;
            }
        }
        public static int IntCellValue(DataGridView dgr, int row, string columnindex)
        {
            try
            {
                return Convert.ToInt32(dgr.Rows[row].Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return 0;
            }
        }
        public static int IntCellValue(DataGridViewRow row, string columnindex)
        {
            try
            {
                return Convert.ToInt32(row.Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return 0;
            }
        }
        public static decimal DecCellValue(DataGridView dgr, int row, string columnindex)
        {
            try
            {
                return Convert.ToDecimal(dgr.Rows[row].Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return 0;
            }
        }
        public static decimal DecCellValue(DataGridViewRow row, string columnindex)
        {
            try
            {
                return Convert.ToDecimal(row.Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return 0;
            }
        }

        public static string StrCellValue(DataGridView dgr, int row, string columnindex)
        {
            try
            {
                return dgr.Rows[row].Cells[columnindex].Value.ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }
        public static string StrCellValue(DataGridViewRow row, string columnindex)
        {
            try
            {
                return row.Cells[columnindex].Value.ToString();
            }
            catch (Exception)
            {
                return "";
            }
        }
        public static DateTime DateCellValue(DataGridView dgr, int row, string columnindex)
        {
            try
            {
                return Convert.ToDateTime(dgr.Rows[row].Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return DateTime.Now;
            }
        }
        public static DateTime DateCellValue(DataGridViewRow row, string columnindex)
        {
            try
            {
                return Convert.ToDateTime(row.Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return DateTime.Now;
            }
        }

        public static bool BoolCellValue(DataGridView dgr, int row, string columnindex)
        {
            try
            {
                return Convert.ToBoolean(dgr.Rows[row].Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static bool BoolCellValue(DataGridViewRow row, string columnindex)
        {
            try
            {
                return Convert.ToBoolean(row.Cells[columnindex].Value);
            }
            catch (Exception)
            {
                return false;
            }
        }
        public static string ThuTrongTuan(DateTime day)
        {
            switch (day.DayOfWeek)
            {
                case DayOfWeek.Monday:
                    return "Thứ Hai";
                case DayOfWeek.Tuesday:
                    return "Thứ Ba";
                case DayOfWeek.Wednesday:
                    return "Thứ Tư";
                case DayOfWeek.Thursday:
                    return "Thứ Năm";
                case DayOfWeek.Friday:
                    return "Thứ Sáu";
                case DayOfWeek.Saturday:
                    return "Thứ Bảy";
                case DayOfWeek.Sunday:
                    return "Chủ Nhật";
                default:
                    return "";
            }
        }

        public static string GetNgay(DateTime day)
        {
            return string.Format(ThuTrongTuan(day) + ", ngày {0}, tháng {1}, năm {2}", day.Day, day.Month, day.Year);
        }
    }
}
